import {
	axios
} from '@/service/request.js'
export const user = {
	state: {
		userInfo: null,
		token: null,
		phone: null
	},
	mutations: {
		setUserInfo(state, userInfo) { // 用户信息
			state.userInfo = userInfo
		},
		setToken(state, token) { // token
			state.token = token
		},
		setPhone(state, phone) { // 手机号，用于判断是否认证
			state.phone = phone
		}
	},
	actions: {
		// 判断用户是否认证（是否个人登录）返回1：已认证，0：未认证
		isAuthentication(content) {
			if (content.state.phone) return 1
			return 0
		},
		// 调用接口获取用户信息（是否个人登录）返回1：已认证，0：未认证
		async getUserInfo({
			commit
		}) {
			const {
				data
			} = await axios('GET', `/nf/api/commons/getBizUser`)
			commit('setUserInfo', data)
			commit('setPhone', data.telephone)
			return data
		},
		login() {
			uni.navigateTo({
				url: '/pages/login/login'
			})
		}
	},
	getters: {
		getUserInfo: (state) => state.userInfo,
		getToken: (state) => state.token,
		getPhone: (state) => state.phone
	}
}
